package cn.mugutu.finance.service.system.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import cn.mugutu.finance.domain.system.DictionaryDetail;
import cn.mugutu.finance.service.system.DictionaryDetailService;
import cn.mugutu.finance.dto.BaseResult;

@Service
public class DictionaryDetailServiceImpl extends BaseServiceImpl<DictionaryDetail>
        implements DictionaryDetailService {

    @Override
    public BaseResult saveOrUpdateDictionaryDetail(DictionaryDetail dictionaryDetail) {
        if (dictionaryDetail.getId() != null) {
            DictionaryDetail oldDtail = get(dictionaryDetail.getId());
            oldDtail.setName(dictionaryDetail.getName());
            oldDtail.setTypes(dictionaryDetail.getTypes());
            update(oldDtail);
            return new BaseResult(true, "更新成功");
        } else {
            if (dictionaryDetail.getTypes() != null) {
                save(dictionaryDetail);
                return new BaseResult(true, "保存成功");
            }
        }
        return new BaseResult(false, "操作失败");
    }

    @Override
    public List<DictionaryDetail> findDictionaryDetailBySn(String sn) {
        return findByHql(" FROM DictionaryDetail o WHERE o.types.sn =  ? ", sn);
    }

}
